package com.whmall.service.crm.module.company.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.whmall.component.enumeration.CompanyTypeEnum;
import com.whmall.service.crm.entity.dto.company.CompanyAddReqDTO;
import org.apache.dubbo.common.utils.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @Description TODO
 * @Author yangkuan
 * @Date 2020/7/31 10:48
 **/
@Component
public class CompanyAddValidator {



    public void validate(CompanyAddReqDTO companyAddReqDTO) {

        if (companyAddReqDTO == null) {
            throw new IllegalArgumentException("req不能为空");
        }

        if (StringUtils.isEmpty(companyAddReqDTO.getName())) {
            throw new IllegalArgumentException("公司中文名称不能为空");
        }

        if (companyAddReqDTO.getEstablishedTime() == null) {
            throw new IllegalArgumentException("公司成立时间不能为空");
        }

        if (companyAddReqDTO.getIsCustomer() == null || companyAddReqDTO.getIsSupplier() == null) {
            throw new IllegalArgumentException("注册行为不能为空");
        }

        if (companyAddReqDTO.getCompanySource() == null) {
            throw new IllegalArgumentException("客户来源不能为空");
        }

        if (CollUtil.isEmpty(companyAddReqDTO.getCompanyTypeList())){
            throw new IllegalArgumentException("公司业务性质不能为空");
        }

        if(StringUtils.isEmpty(companyAddReqDTO.getIntroduce())){
            throw new IllegalArgumentException("公司介绍不能为空");
        }

        if (companyAddReqDTO.getProvince() == null || companyAddReqDTO.getProvince() == 0) {
            throw new IllegalArgumentException("地址不能为空");
        }

        if (companyAddReqDTO.getCity() == null || companyAddReqDTO.getCity() == 0) {
            throw new IllegalArgumentException("地址不能为空");
        }

        if (companyAddReqDTO.getDistrict() == null || companyAddReqDTO.getDistrict() == 0) {
            throw new IllegalArgumentException("地址不能为空");
        }

        if (StringUtils.isEmpty(companyAddReqDTO.getAddress())) {
            throw new IllegalArgumentException("详细地址不能为空");
        }

        if(companyAddReqDTO.getCompanyTypeList().stream().noneMatch(c -> c.getFirstType().equals(CompanyTypeEnum.SCHOOL_ORG.getValue()))){

            if (companyAddReqDTO.getRegisteredCapital() == null || companyAddReqDTO.getRegisteredCapital() < 0) {
                throw new IllegalArgumentException("注册资金不能为空或者负数");
            }

            if(companyAddReqDTO.getCompanyScale() == null){
                throw new IllegalArgumentException("公司规模不能为空");
            }
        }


    }
}
